<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>测试http服务</title>
  </head>
  <body>
    <form action="/" method="get">
      <input type="text" name="uname" id="uname" />
      <input type="text" name="upwd" id="upwd" />
      <button type="button" onclick="send()">发射</button>
    </form>
  </body>
  <script>
    function $(e) {
      return document.querySelector(`#${e}`);
    }
    function send() {
      if (window.XMLHttpRequest) {
        var xhr = new XMLHttpRequest();
      } else {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
      }
      xhr.open(
        "get",
        `/?uname=${$("uname").value}&upwd=${$("upwd").value}`,
        true
      );
      xhr.send();
      xhr.onreadystatechange = () => {
        if (xhr.readyState == 4 && xhr.status == 200) {
          console.log(xhr.responseText);
        } else {
          console.log(xhr.status);
        }
      };
    }
  </script>
</html>
